home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 630 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.0 KB  |  128 lines

  1. Newsgroups: comp.lang.c
  2. Path: gail.ripco.com!mambuhl
  3. From: mambuhl@ripco.com (Martin Ambuhl)
  4. Subject: Re: Two strange C problems.
  5. X-Nntp-Posting-Host: foley.ripco.com
  6. Message-ID: <DKuJHw.Dsu@rci.ripco.com>
  7. Sender: usenet@rci.ripco.com (Net News Admin)
  8. Organization: Ripco Internet BBS Chicago
  9. X-Newsreader: TIN [version 1.2 PL2]
  10. Date: Mon, 8 Jan 1996 05:05:55 GMT
  11. X-Ident-Sender: mambuhl
  12.  
  13. cs102238@lux.latrobe.edu.au (Gregary John Boyles )
  14. in <4cojb2$qog@lugb.latrobe.edu.au> wrote:
  15.  
  16. > I have two C problems.
  17.  
  18. And what are they?  You have problems, all right.  Are they C problems?
  19. Maybe, but there is no way to tell when your code is all dos-isms.  Just
  20. to compile this junk required me to add the following at the beginning.
  21. If it doesn't look like it does what you expect, no big deal.  Your
  22. non-standard functions, structs, and macros can be defined any way one
  23. wants, as long as there are no syntax problems as a result.  The
  24. semantics are completely undefined.
  25.  
  26. /* BEGINNING prologue */
  27. #include <stdio.h>
  28. typedef struct {
  29.     short screenheight, screenwidth;
  30. }   text_info;
  31. typedef struct { /* warning: no members */
  32. }  *nodetypeptr;
  33.  
  34. #define initialize(x)
  35. #define cputs   puts
  36. #define cprintf   printf
  37. #define maxstring BUFSIZ
  38. #define removelineends(x,y)
  39. #define add(x,y,z)
  40. #define gettextinfo(x)
  41. #define getcolors(a,b,c,d)
  42. #define _setcursortype(x)
  43. #define clrscr()
  44. #define textcolor(x)
  45. #define textbackground(x)
  46. #define gotoxy(x,y)
  47. #define writescreenfull(a,b,c,d,e,f,g);
  48. #define setpos(x,y)
  49. #define displayhelp(x,y,z)
  50. #define readstring(a,b,c,d,e)
  51. #define searchstring()
  52. #define empty(x)    0
  53. #define remove(y)               /* note: remove is a reserved
  54.                                  * identifier (see stdio) */
  55. #define getch() getchar()
  56. #define window(a,b,c,d)
  57.  
  58. char line[maxstring], bottomline[maxstring];
  59. enum {
  60.     LIGHTGRAY, BLACK, _NOCURSOR, _NORMCURSOR, space, escape, up, down,
  61.     pageup, pagedown, left, right, end_, home, search, help, nul
  62. }; /* note: _Nxxx are reserved identifiers */
  63.  
  64. /* END prologue */
  65.  
  66. [snip - line after line of M$dog-isms]
  67.  
  68. >This program should exit such that the screen is clear with the DOS
  69. >prompt in the upper left corner, ...
  70.  
  71. Why should it?  C doesn't even have such a concept as "screen".  If
  72. your implementation provides such functions, learn to use them or call
  73. their technical support, or pay someone to debug your crap.
  74.  
  75. >..., but no, it exits with a short line
  76. >of text on the first line and then the DOS prompt on the next
  77. >line.I never(or rarely) have these sort of problems with Pascal so
  78. >why do they continuously crop up with C.
  79.  
  80. Your problems have NOTHING to do with C.  If you can't tell the
  81. difference, then go back to whatever you have confused with Pascal.
  82.  
  83. >
  84. >
  85. > PROBLEM 2 :
  86. >
  87. > const escape=27; const cr=13; const bs=8;
  88. >
  89. > while (ch!=cr) { . . . }
  90. >
  91. > while (ch!=escape) { . . . }
  92. >
  93. > If I replace the 27 with \27' or the 13 with '\13' then these loops
  94. > don't work i.e. an infinite loop results. WHY?
  95.  
  96. Clever.  You have worked out that octal and decimal are not the same.
  97. Just a hint:
  98. \13 == 11
  99. \15 == 13
  100. \27 == 23
  101. \33 == 27
  102.  
  103.  
  104. > Also if I want to do somthing like this : puts("\24 \25"); which
  105. > should print the up and down arrows on the screen (ASCII 24 and
  106. > 25), but no, it prints some other ASCII characters. As far as I can
  107. > tell C has its own unique character table, at least for the control
  108. > characters. WHY?
  109.  
  110. The IBM-extended character set (_not_ ASCII) defines the Up arrow and
  111. Down arrow as \30 == 24 and \31 == 25 (\24 == 20 is a paragraph sign.
  112. \25 == 21 is a section sign).  This has nothing to do with C (except for
  113. the use of \ooo for octal chars), and nothing to do with ASCII.  The
  114. world is not defined by your PC-toy.
  115.  
  116. > Sometimes I wonder whether some one needs to go back an rewrite the
  117. > damn language so that it works sensibly and predictably like Pascal
  118. > can be relied upon to do.
  119.  
  120. Learning how to read would be a hell of a lot more useful.  The only
  121. thing here which does not work sensibly and predictably is your brain.
  122.  
  123.  
  124.  
  125. --
  126. * Martin Ambuhl       net: mambuhl@ripco.com
  127. * Chicago, IL (USA)    
  128.